package com.woniu.user.exception;


import com.woniu.common.result.Result;
import com.woniu.common.result.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({Exception.class})
    public Result handler(Exception e){
        e.printStackTrace();
        if(e instanceof SQLIntegrityConstraintViolationException){
            return Result.error(ResultCode.USER_HAS_EXISTED.getCode(),ResultCode.USER_HAS_EXISTED.getMessage());
        }
        return Result.error();
    }
}
